package com.lhj.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhj.reggie.common.R;
import com.lhj.reggie.entity.Category;
import com.lhj.reggie.service.CategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 分类管理
 */
@RestController
@RequestMapping("category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    /**
     * 新增分类
     *
     * @param category
     * @return
     */
    @PostMapping
    public R<String> insert(@RequestBody Category category) {
        return categoryService.insert(category);
    }

    /**
     * 分类查询
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R<Page> page(int page, int pageSize) {
        return categoryService.page(page, pageSize);
    }

    /**
     * 根据ids删除分类，判断分类有无关联菜品或套餐
     *
     * @param ids
     * @return
     */
    @DeleteMapping()
    public R<String> remove(Long ids) {
        return categoryService.remove(ids);

    }

    /**
     * 修改分类信息
     *
     * @param category
     * @return
     */
    @PutMapping
    public R<String> update(@RequestBody Category category) {
        return categoryService.update(category);
    }

    /**
     * 根据条件查询分类数据
     *
     * @param category
     * @return
     */
    @GetMapping("/list")
    public R<List<Category>> list(Category category) {
        return categoryService.list(category);
    }
}
